package models

import (
	"192.168.1.75/go-pkg/helper"
	"gorm.io/gorm"
)

// FloorDevice 楼层关联设备
type FloorDevice struct {
	ID         string `json:"id" gorm:"column:id;primaryKey;type:int;size:64;comment:主键id"`
	FloorID    string `json:"floor_id" gorm:"column:floor_id;index:floor_id;type:int;size:64;comment:楼层id"`
	RobotID    string `json:"robot_id" gorm:"column:robot_id;index:robot_id;type:string;size:40;comment:设备id"`
	PositionID string `json:"position_id" gorm:"column:position_id;index:position_id;type:int;size:64;comment:位置点"`
	CreatedAt  int64  `json:"created_at,omitempty" gorm:"column:created_at;autoCreateTime;type:int;size:64;comment:创建时间"`
	UpdatedAt  int64  `json:"updated_at,omitempty" gorm:"column:updated_at;autoUpdateTime;type:int;size:64;comment:更新时间"`
}

// TableName 表名
func (FloorDevice) TableName() string {
	return "floor_device"
}

// BeforeCreate 自增id
func (l *FloorDevice) BeforeCreate(tx *gorm.DB) (err error) {
	if l.ID != "" {
		return nil
	}
	// 用户id为空时，自动添加用户id
	uuid, err := helper.UUID{}.String()
	if err != nil {
		return err
	}
	l.ID = uuid
	return nil
}

// 模式自动注册
func init() {
	Models = append(Models, &FloorDevice{})
}
